from pydantic import BaseModel, Field, ConfigDict, EmailStr
from datetime import datetime
from typing import Optional, List


# 用户models的序列化类
class MailOutSchema(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int = Field(description="邮件ID")
    receiver: str = Field(description="收件人")
    subject: str = Field(description="邮件主题")
    content: str = Field(description="邮件内容")
    realname: Optional[str] = Field(default=None, description="发送者姓名")
    create_at: datetime = Field(description="创建时间")


class MailQueryModel:
    def __init__(
        self,
        receiver: Optional[str] = None,
        subject: Optional[str] = None,
        content: Optional[str] = None,
        page: int = 1,
        limit: int = 10,
    ):
        self.receiver = receiver
        self.subject = subject
        self.content = content
        self.page = page
        self.limit = limit


class MailSaveModel(BaseModel):
    receiver: EmailStr = Field(..., description="收件人")
    subject: str = Field(..., description="邮件主题")
    content: str = Field(..., description="邮件内容")
